package com.thh.core.manager;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class DataSourcePoolManager {

    private Map<String, DruidDataSource> dataSourcePoolManagerMap = new HashMap<>();

    public Map<String, DruidDataSource> getDataSourcePoolManagerMap() {
        return dataSourcePoolManagerMap;
    }

    public void setDataSourcePoolManagerMap(Map<String, DruidDataSource> dataSourcePoolManagerMap) {
        this.dataSourcePoolManagerMap = dataSourcePoolManagerMap;
    }

    public void deleteDruidDataSource(Long dbId) {
        String dbIdStr = String.valueOf(dbId);
        deleteDruidDataSource(dbIdStr);
    }

    public void deleteDruidDataSource(String dbIdStr) {
        if(dataSourcePoolManagerMap.containsKey(dbIdStr)) {
            dataSourcePoolManagerMap.remove(dbIdStr);
        }
    }
}
